using System;
using System.Collections.Generic;

namespace Utility
{
    /// <summary>
    /// Generic utility class to allow building of resource files into multiple formats
    /// </summary>
    public class ResourceListBuilder
    {
        /// <summary>
        /// Allows the return of a collection (for contains based fast lookups based on a resource 
        /// with any chosen string based delimeter
        /// </summary>
        /// <param name="splitter"></param>
        /// <param name="listToSplit"></param>
        /// <returns></returns>
        public ICollection<string> ConvertResourceToCollection(string splitter, string listToSplit)
        {
            String[] splitterArray = new String[1];
            splitterArray[0] = splitter;
            return ConvertResourceToCollection(splitterArray, listToSplit);
        }

        /// <summary>
        /// Allows the return of a collection (for contains based fast lookups based on a resource 
        /// with carriage return, line feed delimiters (\r\n)
        /// </summary>
        /// <param name="listToSplit"></param>
        /// <returns></returns>
        public ICollection<String> ConvertResourceToCollection(String listToSplit)
        {
            return ConvertResourceToCollection("\r\n", listToSplit);
        }

        /// <summary>
        /// Allows the return of a collection (for contains based fast lookups based on a resource 
        /// with mulitple delimeters
        /// </summary>
        /// <param name="splitter"></param>
        /// <param name="listToSplit"></param>
        /// <returns></returns>
        public ICollection<string> ConvertResourceToCollection(string[] splitter, string listToSplit)
        {
            ICollection<String> collection = new List<String>();
            foreach (String s in listToSplit.Split(splitter, StringSplitOptions.RemoveEmptyEntries))
            {
                collection.Add(s);
            }
            return collection;
        }
    }
}
